words = ["I","am","a","student","from","a","university","in","a","city"], word1 = "a", word2 = "student"
var findclosest = function(words,word1,word2){
    let a = -1
    let b = -1
    let res = words - 1
    for(i = 0;i <= res;i ++){
        if(words[i] == word1){
            a = i
        }
        if(words[i] == word2){
            b = i
        }
        if(a !== -1 && b !== -1){
            res = Math.min(res,Math.abs(a - b))
        }
        if(res == 1){
            return res
        }
    }
    return res
}